//- Copyright (c) 2016 Lucky Byte, Inc.
extends ../layout

append scripts
  script(src="/js/terms/check.js")

block content
  form.ui.form.attached.segment.main(action="/terms/check" method="post")
    .ui.large.label.right.ribbon.blue.nolayout 以下信息由 
      span(style="color:yellow;") #{record.input_user || '未知'} 
      | 于 
      span(style="color:yellow;") #{record.input_time.format('YYYY-MM-DD HH:mm:ss')} 
      | 修改，请复核 ...

    if record.checked && record.checker == userinfo.uuid
      .ui.label.top.left.attached.pink.nolayout 您在 
        span(style="color:yellow;") #{record.check_time.format('YYYY-MM-DD HH:mm:ss')} 
        | 复核过该信息，生效时间为 
        span(style="color:yellow;") #{record.effect_time.format('YYYY-MM-DD HH:mm:ss')} 
    else if record.reject_reason && record.reject_reason.length > 0
      .ui.label.top.left.attached.pink.nolayout 上次用户 
        span(style="color:yellow;") #{record.check_user} 
        | 拒绝了此信息，原因：
        span(style="color:yellow;") #{record.reject_reason} 

    input(type="hidden" name="serial" value="#{record.serial || ''}")
    input(type="hidden" name="uuid" value="#{record.uuid || ''}")
    input(type="hidden" name="input_time"
      value="#{record.input_time.format('YYYY-MM-DD HH:mm:ss')}")
    input(type="hidden" name="action" value="pass")

    table.ui.table.celled.basic.selectable#check
      thead
        tr
          th.center.aligned 名 称
          th.center.aligned 原 值
          th.center.aligned 新 值
          th.collapsing(data-content="点击过滤相同的行" data-variation="small")
            a#same_filter(href="#") 一致
          th.collapsing(data-content="点击勾选全部" data-variation="small")
            a#check_all(href="#") 复核
      tbody
        -
          items = [
            {
              label: '基本信息', subitems: [
                { key: 'termid', title: '终端编号' },
                { key: 'merid', title: '隶属商户' },
                { key: 'mapto_term', title: '外联终端' },
                { key: 'tmk', title: '终端主密钥' },
                { key: 'macalgo', title: 'MAC算法' }]
            }, {
              label: '备注信息', subitems: [
                { key: 'notes', title : '备注' }]
            }]
        each item in items
          tr
            td(colspan="5" data-same="false")
              .ui.ribbon.label.brown= item.label
          each subitem in item.subitems
            - var ref_val = ref_record[subitem.key] || ''
            - var new_val = record[subitem.key] || ''
            - var same = ref_val == new_val
            tr(class="#{same ? '' : 'error'}" data-same="#{same}")
              td= subitem.title
              if subitem.key == 'merid'
                td.center.aligned #{ref_record.mer_name}
                  <br/>
                  | #{ref_record.mer_no} ｜ 
                  | #{ref_record.mer_inside ? '平台商户' : '外联商户'} ｜ 
                  | #{constant.merch_chnls[ref_record.mer_chnl]}
                td.center.aligned #{record.mer_name}
                  <br/>
                  | #{record.mer_no} ｜ 
                  | #{record.mer_inside ? '平台商户' : '外联商户'} ｜ 
                  | #{constant.merch_chnls[record.mer_chnl]}
              else if subitem.key == 'mapto_term'
                td.center.aligned= ref_record.mapto_term_id
                td.center.aligned= record.mapto_term_id
              else if subitem.key == 'assoc_term'
                td.center.aligned= ref_record.assoc_term_id
                td.center.aligned= record.assoc_term_id
              else if subitem.key == 'trctl'
                td.center.aligned= ref_record.trctl_name
                td.center.aligned= record.trctl_name
              else if subitem.key == 'macalgo'
                td.center.aligned= constant.macalgos[ref_record.macalgo]
                td.center.aligned= constant.macalgos[record.macalgo]
              else
                td.center.aligned= ref_record[subitem.key]
                td.center.aligned= record[subitem.key]

              td.center.aligned= same ? '是' : '否'
              td.center.aligned(style="padding-bottom:2px;")
                .ui.checkbox
                  if same
                    input(type="checkbox" checked="checked")
                    label
                  else
                    input(type="checkbox")
                    label

    .fields#effect_time(style="display:none;")
      .field.eight.wide
        label 生效时间:
        .ui.calendar.datetime#effect_time
          .ui.input.left.icon
            i.calendar.icon
            input(type="text" name="effect_time")

    .fields#reject_reason(style="display:none;")
      .field.sixteen.wide
        label 拒绝原因:
        textarea(name="reject_reason" type="text" rows="3"
          placeholder="请输入拒绝的原因")

    .ui.buttons(style="margin-top:40px;")
      if page_perms.check
        button.ui.red.button#reject(type="button") 拒 绝
      else
        button.ui.red.button.disabled#reject(type="button")
          i.icon.ban.grey
          | 拒 绝

      button.ui.yellow.button#cancel(type="button"
        onclick="window.location = '/terms'") 取 消

      if page_perms.check
        button.ui.green.button.disabled#pass(type="button") 通 过
      else
        button.ui.green.button.disabled#pass(type="button")
          i.icon.ban.grey
          | 通 过
